package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeTech;
import com.ruoyi.grape.service.IGrapeTechService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/tech")
public class GrapeTechController extends BaseController
{
    @Autowired
    private IGrapeTechService grapeTechService;

    /**
     * 查询文章列表
     */
    @PreAuthorize("@ss.hasPermi('grape:tech:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeTech grapeTech)
    {
        startPage();
        List<GrapeTech> list = grapeTechService.selectGrapeTechList(grapeTech);
        return getDataTable(list);
    }

    /**
     * 导出文章列表
     */
    @PreAuthorize("@ss.hasPermi('grape:tech:export')")
    @Log(title = "文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeTech grapeTech)
    {
        List<GrapeTech> list = grapeTechService.selectGrapeTechList(grapeTech);
        ExcelUtil<GrapeTech> util = new ExcelUtil<GrapeTech>(GrapeTech.class);
        util.exportExcel(response, list, "文章数据");
    }

    /**
     * 获取文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:tech:query')")
    @GetMapping(value = "/{techId}")
    public AjaxResult getInfo(@PathVariable("techId") Long techId)
    {
        return success(grapeTechService.selectGrapeTechByTechId(techId));
    }

    /**
     * 新增文章
     */
    @PreAuthorize("@ss.hasPermi('grape:tech:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeTech grapeTech)
    {
        return toAjax(grapeTechService.insertGrapeTech(grapeTech));
    }

    /**
     * 修改文章
     */
    @PreAuthorize("@ss.hasPermi('grape:tech:edit')")
    @Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeTech grapeTech)
    {
        return toAjax(grapeTechService.updateGrapeTech(grapeTech));
    }

    /**
     * 删除文章
     */
    @PreAuthorize("@ss.hasPermi('grape:tech:remove')")
    @Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{techIds}")
    public AjaxResult remove(@PathVariable Long[] techIds)
    {
        return toAjax(grapeTechService.deleteGrapeTechByTechIds(techIds));
    }
}
